package com.woniuxy.controller;

import com.woniuxy.model.House;
import com.woniuxy.result.Result;
import com.woniuxy.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("house")
public class HouseController {

    @Autowired
    private HouseService houseService;
    //增加房间
    @PostMapping("insert")
    public Result addHouse(@RequestBody House house){
        //新增房间
        houseService.insertHouse(house);
        return Result.success().msg("新增成功!!");
    }

    //删除房间信息
    @DeleteMapping("delete/{id}")
    public Result deleteHouse(@PathVariable Integer id){
        houseService.deleteById(id);
        return Result.success().msg("删除成功");
    }

    //修改信息
    @PutMapping("update")
    public Result updateById(@RequestBody House house){
        houseService.updateById(house);
        return Result.success().msg("修改成功");
    }

    //分页查询所有房间及其所属楼栋信息
    @GetMapping("getall/{page}/{size}")
    public Result getAll(@PathVariable Integer page,@PathVariable Integer size){
        List<House> houses = houseService.getAll(page,size);
        return Result.success(houses).msg("查询成功");
    }

    //根据id进行房间信息的查询
    @GetMapping("getbyid")
    public Result getById(@RequestParam("uid") Integer id){
        House house = houseService.selectById(id);
        return Result.success(house).msg("查询单个房间信息成功");
    }

}
